package com.sansan.qiangji.service.impl.system;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sansan.qiangji.entity.system.Power;
import com.sansan.qiangji.form.system.power.PowerListForm;
import com.sansan.qiangji.mapper.system.PowerMapper;
import com.sansan.qiangji.service.inter.system.PowerService;
import com.sansan.qiangji.utils.pageUtils.PageResult;
import com.sansan.qiangji.utils.pageUtils.PageUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PowerServiceImpl implements PowerService {
    private PowerMapper powerMapper;

    @Resource
    public void setPowerMapper(PowerMapper powerMapper) {
        this.powerMapper = powerMapper;
    }

    @Override
    public List<Power> findAllPower() {
        return powerMapper.findAllPower();
    }

    @Override
    public PageResult<Power> powerList(PowerListForm powerListForm) {
        int pageNum = powerListForm.getPageNum();
        int pageSize = powerListForm.getPageSize();
        PageHelper.startPage(pageNum, pageSize);
        Power power = new Power();
        power.setPowerName(powerListForm.getPowerName());
        power.setPowerPath(powerListForm.getPowerPath());
        power.setPowerGroup(powerListForm.getPowerGroup());
        power.setPowerStatus(powerListForm.getPowerStatus());
        List<Power> powers = powerMapper.powerList(power);
        return PageUtil.getPageResult(new PageInfo<>(powers));
    }

    @Override
    public Power findByPowerId(Integer powerId) {
        return powerMapper.findByPowerId(powerId);
    }

    @Override
    public List<Power> findByPowerName(String powerName) {
        return powerMapper.findByPowerName(powerName);
    }

    @Override
    public int addPower(Power power) {
        return powerMapper.addPower(power);
    }

    @Override
    public int updatePower(Power power) {
        return powerMapper.updatePower(power);
    }

    @Override
    public int deleteById(Integer powerId) {
        return powerMapper.deleteById(powerId);
    }
}
